#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9+7,M = 1e7;
int t,n,v[M+10],v1[20],mx;
signed main()
{
	freopen("give.in","r",stdin);
	freopen("give.out","w",stdout);
	scanf("%lld",&t);
	for(int i = 1;i <= M;i++) 
	{
		v[i] = v[i-1];
		int j = i;
		while(j)
		{
			v1[j%10]++;
			j /= 10;
		}
		mx = 0;
		for(int j = 1;j <= 9;j++)
			if(v1[j] >= v1[mx]) mx = j;
		for(int j = 0;j <= 9;j++) v1[j] = 0;
		v[i] += mx;
		if(v[i]>mod) v[i] -= mod;
	}
	while(t--)
	{
		scanf("%d",&n);
		printf("%d\n",v[n]);
	}
	return 0;
}


